package com.ddc.study.util;

import android.content.Context;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

/**
 * Created on 2018/4/28.
 *
 * @author lshun
 * @version 1.0
 */
public class ToastUtil {
    private ToastUtil() {
    }

    private static Toast sToast;

    public static void showToast(@NonNull Context context, @StringRes int resId) {
        showToast(context, context.getString(resId));
    }

    public static void showToast(@NonNull Context context, @NonNull String text) {
        if (sToast == null) {
            sToast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_SHORT);
            sToast.show();
        } else {
//            sToast.cancel();
            sToast.setText(text);
            sToast.setDuration(Toast.LENGTH_SHORT);
            sToast.show();
        }
    }
}
